/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package beanControl;

import Utils.Helper;
import Utils.JDBCHelper;
import Utils.StringUtility;
import beanInfo.users;
import java.util.ArrayList;
import javax.swing.JTable;

/**
 *
 * @author MiA
 */
public class userControl {

    ArrayList<String> listColumn = new ArrayList<String>();
    ArrayList<String> listValue = new ArrayList<String>();
    users us = new users();

    public void getlistUsers(JTable table) {

        String sql = "select UserName,Password,Name,Birthday,Email,Address,Role,Gender,Phone,Status from Users";
        String[] header = {"UserName", "Password", "Name", "Birthday", "Email", "Address", "Gender", "Role", "Phone", "Status"};
        Helper.loadDataTable(sql, table, header);

    }

    public void insertUser(users us) {
        Object[] values = {us.getUserName(), us.getPassWord(), us.getName(), us.getBirthday(), us.getEmail(), us.getAddress(), us.getGender(), us.getRole(), us.getPhone(), us.getStatus()};
        JDBCHelper.excuteInsertPlaceHolder("Users", 10, values);
        Helper.successMessage("Insert  successfull", "furniture");

    }

    public void updateUser(users us) {
        String[] objColumn = {"UserName","Name","Email","Address","Roles","Gender","Phone","Status "};
        String[] objValues = {us.getUserName(), us.getName(), us.getEmail(), us.getAddress(), us.getRole(), us.getGender(), us.getPhone(),us.getStatus()};

        listColumn = (ArrayList<String>) StringUtility.ArrayToArrayList(objColumn);
        listValue = (ArrayList<String>) StringUtility.ArrayToArrayList(objValues);
        JDBCHelper.executeUpdate("Users", listColumn, listValue, "UserName", us.getUserName());
        Helper.successMessage("Update Sucessful", "furniture");
    }

    private boolean  checkDelteCategories(String values) {
        return JDBCHelper.excuteDelete("UserName", "LoanProfile", values);
    }

    public void DeleteUser(users us) {
        if (checkDelteCategories((us.getUserName()))==true) {
            Helper.inforMessage("Can not detlete this User this is using", "furniture");
        } else {
            JDBCHelper.excuteDelete("Users", "UserName", us.getUserName());
            Helper.successMessage("Delete successfull", "furniture");
        }
    }

    public void checkUser() {
    }
}
